package com.happok.onlineclass.usermanagement.authentication.controller;

import com.happok.onlineclass.usermanagement.authentication.dto.LoginResultDTO;
import com.happok.onlineclass.usermanagement.authentication.dto.VerifyCodeLoginDTO;
import com.happok.onlineclass.usermanagement.authentication.service.AuthenticationService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 鉴权管理
 * 功能说明
 *
 * @author : chenac
 * @module 在线课堂/用户管理          yapi 项目组/子项目
 * @date : 2021/6/28 13:34
 */
@Api(tags = "鉴权管理")
@RestController
@RequestMapping(value = "/user-management/auth")
public class AuthenticationController {

    @Autowired
    private AuthenticationService authenticationService;

    /**
     * 用户登录
     * 用户登录 <br>
     * 记住我，问号后参数remember-me，取值on/yes/1/true<br>
     * 20000,用户登录成功<br>
     * 40103,账号或密码错误<br>
     * 40104,账户被禁用<br>
     * 40105,登录失败
     *
     * @param basicAuth 用户鉴权信息，使用http Basic方式, Basic eWMyOjE5OTUwwWWM=，客户端将用户名和密码中间用“：”分隔合并，并将合并后的字符串用BASE64编码，在每次请求数据 时，将密文附加于请求头（Request Header）Authorization: Basic XXXXXXX中
     * @author: chenac
     * @date: 17:02
     * @execption:
     * @return: com.happok.onlineclass.usermanagement.authentication.dto.LoginResultDTO
     */
    @PostMapping(value = "/login/v1")
    @ApiOperation(value = "用户登录")
    @ApiResponses({
            @ApiResponse(code = 20000, message = "用户登录成功"),
            @ApiResponse(code = 40103, message = "账号或密码错误"),
            @ApiResponse(code = 40104, message = "账户被禁用"),
            @ApiResponse(code = 40105, message = "登录失败")
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户鉴权信息，使用http Basic方式, Basic eWMyOjE5OTUwwWWM=，客户端将用户名和密码中间用“：”分隔合并，并将合并后的字符串用BASE64编码，在每次请求数据 时，将密文附加于请求头（Request Header）Authorization: Basic XXXXXXX中", required = true),
            @ApiImplicitParam(name = "remember-me", value = "on/yes/1/true", required = false)
    })
    public LoginResultDTO login(@RequestHeader(value = "Authorization") String basicAuth) {
        return authenticationService.login(basicAuth);
    }

    /**
     * 用户登录-验证码
     * 20000,用户登录成功<br>
     * 40104,账户被禁用<br>
     * 40105,登录失败<br>
     * 41004,验证码登录功能设置异常<br>
     * 41201,验证码不正确<br>
     * 41202,验证码失效
     *
     * @param verifyCodeLogin
     * @author: chenac
     * @date:  9:44
     * @execption:
     * @return: com.happok.onlineclass.usermanagement.authentication.dto.LoginResultDTO
     */
    @PostMapping(value = "/login/verification/v1")
    @ApiOperation(value = "用户登录-验证码")
    @ApiResponses({
            @ApiResponse(code = 20000, message = "用户登录成功"),
            @ApiResponse(code = 40104, message = "账户被禁用"),
            @ApiResponse(code = 40105, message = "登录失败"),
            @ApiResponse(code = 41004, message = "验证码登录功能设置异常"),
            @ApiResponse(code = 41201, message = "验证码不正确"),
            @ApiResponse(code = 41202, message = "验证码失效")
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "remember-me", value = "on/yes/1/true", required = false)
    })
    public LoginResultDTO verifyCodeLogin(VerifyCodeLoginDTO verifyCodeLogin) {
        return authenticationService.loginAccount(verifyCodeLogin.getAccount());
    }

    /**
     * 用户注销
     * 用户注销 <br>
     * 20000，注销成功
     *
     * @param
     * @author: chenac
     * @date: 17:03
     * @execption:
     * @return: void
     */
    @DeleteMapping(value = "/logout/v1")
    @ApiOperation(value = "用户注销")
    @ApiResponse(code = 20000, message = "退出登录成功")
    public void logout() {

    }

    /**
     * 用户刷新session
     *
     * @param
     * @author: chenac
     * @date: 10:01
     * @execption:
     * @return: void
     */
    @GetMapping("/login/rememberme/refresh/v1")
    @ApiOperation(value = "用户刷新session")
    @ApiResponse(code = 20000, message = "刷新session成功")
    public void refresh() {

    }
}